package net.obxlabs.tweetpad.test;
import java.awt.*;
import processing.core.*;
import twitter4j.*;

public class T1TwitterProfile {
    public static final int FILL = 0;
    public static final int STROKE = 1;
    public static final int MARGIN = 6;
    public static final int THUMB_SIZE = 48;
    
    private static PApplet p;
    private UserWithStatus userData;
    private PImage thumbnail;
    
    public T1TwitterProfile(UserWithStatus userWithStatus, PApplet parent) {
        userData = userWithStatus;
        p = parent;
        thumbnail = p.loadImage(userData.getProfileImageURL().toString());
    }
    
    public void draw(int x, int y) {
        p.rectMode(PConstants.CENTER);
        setColorFromHex(userData.getProfileTextColor(), STROKE);
        setColorFromHex(userData.getProfileBackgroundColor(), FILL);
        p.rect(x, y, THUMB_SIZE+MARGIN*2, THUMB_SIZE+MARGIN*2);
        p.image(thumbnail, x-THUMB_SIZE/2, y-THUMB_SIZE/2, THUMB_SIZE, THUMB_SIZE);
    }
    
    public static void setColorFromHex(String hexColor, int type) {
        Color color = new Color(Integer.parseInt(hexColor, 16));
        if (type == FILL) {
            p.fill(color.getRed(), color.getGreen(), color.getBlue());
        } else if (type == STROKE) {
            p.stroke(color.getRed(), color.getGreen(), color.getBlue());
        }
    }
}
